package info.fernandoguillen.javadb2.tests;

import info.fernandoguillen.javadb2.Message;
import info.fernandoguillen.javadb2.MessageManager;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * <p>
 * </p>
 * 
 * @internal_author fguillen.mail@gmail.com
 * @date 15/04/2008
 *
 */
public class TestHibernateMain {
	private static final Logger log = 
		Logger.getLogger( TestHibernateMain.class );

    public static void main(String[] args) {
    	if( log.isDebugEnabled() ) {
			log.debug( "main:INI" );
			log.debug( "args:" + args );
		}

    	log.info( "testing insert into" );
    	log.info( "=================" );
    	MessageManager.insertMessage( "Hola Mundo 002" );
    	
    	log.info( "testing get all" ); 
    	log.info( "=================" );
    	List messages = MessageManager.getAll();
        log.info( messages.size() + " message(s) found:" );
        for ( Iterator iter = messages.iterator(); iter.hasNext(); ) {
            Message loadedMsg = (Message) iter.next();
            log.info( loadedMsg.getText() );
        }

        log.info( "testing remove" );
        log.info( "=================" );
        Message message = MessageManager.insertMessage( "Prueba que vamos a borrar" );
        MessageManager.removeMessageById( message.getId() );
        
    	if( log.isDebugEnabled() ) {
			log.debug( "main:END" );
		}
    }
}
